package com.xyht.sca_s.student_manage_system.modules.trainingSchool.controller;


import com.xyht.sca_s.student_manage_system.common.annotation.RequestPass;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonCodeEnum;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.common.desEncodeAndDecode.annotation.SecretBody;
import com.xyht.sca_s.student_manage_system.modules.trainingSchool.entity.req.SmsTsTrainingInfoReq;
import com.xyht.sca_s.student_manage_system.modules.trainingSchool.entity.req.TrainingInfoBatchExportReq;
import com.xyht.sca_s.student_manage_system.modules.trainingSchool.service.SmsTsTrainingInfoService;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.entity.req.FeesRecordBatchExportReq;
import com.xyht.sca_s.student_manage_system.modules.welcomeNewStudent.entity.req.SmsWnsIdListReq;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.concurrent.Future;

/**
 * <p>
 * 培训信息表 前端控制器
 * </p>
 *
 * @author XYHT
 * @since 2024-05-18
 */
@RestController
@SecretBody
@RequestMapping("/trainingSchool/trainingInfo")
public class SmsTsTrainingInfoController {
    @Resource
    private SmsTsTrainingInfoService smsTsTrainingInfoService;

    @RequestPass
    @ApiOperation(value = "填写培训信息并支付")
    @PostMapping("/payment")
    public ResponseResult payment(@RequestBody SmsTsTrainingInfoReq req) {
        return smsTsTrainingInfoService.payment(req);
    }

    @ApiOperation(value = "删除培训信息")
    @PostMapping("/delete")
    public ResponseResult delete(@RequestBody SmsWnsIdListReq req) {
        smsTsTrainingInfoService.removeByIds(req.getIdList());
        return CommonResult.success();
    }

    @ApiOperation(value = "修改培训信息")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody SmsTsTrainingInfoReq req) {
        return smsTsTrainingInfoService.update(req);
    }

    @ApiOperation(value = "培训信息列表")
    @GetMapping("/list")
    public ResponseResult list(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                               @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
                               @RequestParam(value = "jobId", required = false) String jobId,
                               @RequestParam(value = "levelId", required = false) String levelId,
                               @RequestParam(value = "isPaid", required = false) Boolean isPaid,
                               @RequestParam(value = "isDeleted", defaultValue = "0") Integer isDeleted,
                               @RequestParam(value = "ss", required = false) String ss) {
        return smsTsTrainingInfoService.list(pageNum, pageSize, jobId, levelId, isPaid, ss, isDeleted);
    }

    @ApiOperation("培训信息批量导出")
    @PostMapping("/batchExport")
    public ResponseResult batchExport(@RequestBody TrainingInfoBatchExportReq req, HttpServletResponse response) {
        ResponseResult responseResult;
        try {
            Future<ResponseResult> future = smsTsTrainingInfoService.batchExport(req, response);
            while (true) {
                if (future.isDone()) {
                    break;
                }
            }
            responseResult = future.get();
        } catch (Exception e) {
            e.printStackTrace();
            responseResult = CommonResult.failed(CommonCodeEnum.FAIL);
        }
        return responseResult;
    }

}

